package com.binance.mbxgateway.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.binance.master.models.APIRequest;
import com.binance.master.models.APIResponse;
import com.binance.mbxgateway.api.IUserStreamApi;
import com.binance.mbxgateway.vo.request.InternalPingStreamRequest;
import com.binance.mbxgateway.vo.request.PingStreamRequest;
import com.binance.mbxgateway.vo.request.StartStreamRequest;
import com.binance.mbxgateway.vo.response.PingSteamResponse;
import com.binance.mbxgateway.vo.response.StartStreamResponse;
import com.binance.mbxgateway.web.service.IUserStreamService;

@RestController
public class UserStreamController implements IUserStreamApi {
    @Autowired
    private IUserStreamService userStreamService;

    @Override
    public APIResponse<StartStreamResponse> internalStartStream(
            @RequestBody @Validated APIRequest<StartStreamRequest> request) throws Exception {
        return APIResponse.getOKJsonResult(this.userStreamService.internalStartStream(request.getBody().getUserId()));
    }

    @Override
    public APIResponse<StartStreamResponse> startStream(@RequestBody @Validated APIRequest<StartStreamRequest> request)
            throws Exception {
        return APIResponse.getOKJsonResult(this.userStreamService.startStream(request.getBody().getUserId()));
    }

    @Override
    public APIResponse<Void> internalPingStream(@RequestBody @Validated APIRequest<InternalPingStreamRequest> request)
            throws Exception {
        this.userStreamService.internalPingStream(request.getBody().getListenKey());
        return APIResponse.getOKJsonResult();
    }

    @Override
    public APIResponse<PingSteamResponse> pingStream(@RequestBody @Validated APIRequest<PingStreamRequest> request)
            throws Exception {
        return APIResponse.getOKJsonResult(this.userStreamService.pingStream(request.getBody().getUserId()));
    }


}
